package studio.xiaoyun.core.service.impl;

import java.time.LocalDateTime;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import studio.xiaoyun.core.dao.IFeedbackDao;
import studio.xiaoyun.core.entity.FeedbackEntity;
import studio.xiaoyun.core.exception.InvalidParameterException;
import studio.xiaoyun.core.exception.XyException;
import studio.xiaoyun.web.ErrorCode;
import studio.xiaoyun.core.service.IFeedbackService;

@Service
public class FeedbackService implements IFeedbackService {

	@Resource
	private IFeedbackDao feedbackDao;
	
	public IFeedbackDao getFeedbackDao() {
		return feedbackDao;
	}

	public void setFeedbackDao(IFeedbackDao feedbackDao) {
		this.feedbackDao = feedbackDao;
	}

	@Override
	public String createFeedback(String title, String text) {
		if(text==null || text.trim().length()==0){
			throw new InvalidParameterException("内容不能为空!");
		}
		if(title==null || title.trim().length()==0){
			title = "网友";
		}
		FeedbackEntity feedback = new FeedbackEntity();
		feedback.setText(text.trim());
		feedback.setTitle(title.trim());
		feedback.setCreateDate(LocalDateTime.now());
		String id = feedbackDao.save(feedback);
        return id;
	}

}
